<!DOCTYPE html>
<html lang="en" style="background:#fff;">
<head>
	<base href="${basePath}">
	<#include "common/top.html"/>
	<style>
		.layui-form-label {
			float: left;
			display: block;
			width: 80px;
			font-weight: 400;
			line-height: 20px;
			text-align: right;
			padding: 9px 15px;
		}
	</style>
</head>
<body style="background:#fff;overflow: hidden">

	<form class="layui-form" modelAttribute="role" name="form1" id="form1"  method="post">
		<div class="layui-form-item-dept">
			<input type="hidden" name="roleId" id="roleId" value="${sysRole.roleId}"/>
			<div class="layui-form-item">
				<label class="layui-form-label"><span style="color: red;">*</span>中文名称：</label>
				<div class="layui-input-inline">
					<input class="layui-input" type="text" maxlength="50" name="roleName" id="roleName" placeholder="这里输入名称" value="${sysRole.roleName}"/>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label"><span style="color: red;">*</span>角色编码：</label>
				<div class="layui-input-inline">
					<input class="layui-input" type="text" name="roleCode"maxlength="20" id="roleCode" placeholder="请输入角色编码" value="${sysRole.roleCode}"/>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">是否启动：</label>
				<div class="layui-input-inline">
					<select id="status" name="status" lay-filter="status">
						<option value="Y">是</option>
						<option value="N">否</option>
					</select>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">应用：</label>
				<div class="layui-input-inline">
					<select id="appId" name="appId" lay-filter="appId">
						<option value="">请选择</option>
					</select>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">备注：</label>
				<div class="layui-input-inline">
					<input class="layui-input" type="text" name="remarks" maxlength="200" id="remarks" placeholder="这里输入备注信息" value="${sysRole.remarks}"/>
				</div>
			</div>

		</div>
	</form>
</body>
	<script type="text/javascript">
		$(document).ready(function(){
			if($("#roleId").val()!=''){
				$("#roleCode").attr("readonly",true);
			}
		});

        layui.use(['form'], function () {
            form = layui.form;
            $form = $('form');

            $("#status  option").each(function(){
                if($(this).val() == "${sysRole.status}") {
                    $(this).attr("selected",true)
                }
            });
            $("#appId  option").each(function(){
                if($(this).val() == "${sysRole.appId}") {
                    $(this).attr("selected",true)
                }
            });

            form.render();
        });
        apps();
        function apps() {
            $.ajax({ url: "${basePath}system/app/getSysAppAll",
                type: "POST",
                success: function(data){
                    if (data.status ==true) {
                        var app = data.t;

                        $("#appId").empty();
                        $("#appId").append('<option value="">请选择</option>');
                        for (var i = 0;i < app.length;i++){
                            $("#appId").append('<option value="'+app[i].appId+'">'+app[i].appName+'</option>')
                        }
                        form.render();
                    }
                }
            })

        }
		//保存
		function save(){
			if(checkIsNull("roleName","请输入角色名称") || checkIsNull("roleCode","请输入角色编码")){
				return false;
			}
			$.ajax({ url: "${basePath}system/role/saveUpdateRole",
				data: $("#form1").serialize(),
				type: "POST",
				success: function(data){
					if (data.status == true) {
                        layer.alert(data.msg,function(index){
                            var index1 = parent.layer.getFrameIndex(window.name); //获取窗口索引
                            parent.layer.close(index1);
                            layer.close(index);
                        });
					}else{
						parent.layer.alert(data.msg);
					}
				}
			})
		}
	</script>
</html>


